#include <iostream>
#include <memory>

using std::cout;
using std::endl;

class Fruit
{
public:
    virtual void show()=0;
    virtual ~Fruit()=default;
};

class Animal
{
public:
    virtual void show()=0;
    virtual ~Animal()=default;
};

class Apple : public Fruit
{
public:
    void show() override
    {
        cout<<"我是一个苹果"<<endl;
    }
};

class Monkey : public Animal
{
public:
    void show() override
    {
        cout<<"我是一个猴子"<<endl;
    }
};


class Factory
{
public:
    virtual std::shared_ptr<Fruit> createFruit()=0;
    virtual std::shared_ptr<Animal> createAnimal()=0;
    virtual ~Factory()=default;
};

class ConcreteFactory:public Factory
{
public:
    std::shared_ptr<Fruit> createFruit() override
    {
        return std::make_shared<Apple>();
    }
    std::shared_ptr<Animal> createAnimal() override
    {
        return std::make_shared<Monkey>();
    }
};

int main()
{
    std::shared_ptr<Factory> ff = std::make_shared<ConcreteFactory>();
    std::shared_ptr<Fruit> fruit=ff->createFruit();
    std::shared_ptr<Animal> animal=ff->createAnimal(); 

    fruit->show();
    animal->show();
    return 0;
}